﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using DynSim.EntityFramework;
using DynSim.Basics;

namespace DynSim
{
    public class BaseEngine : GameComponent
    {
        public EntityCollection entities = new EntityCollection();
        public Camera camera;
        
        Game game;

        public GraphicsDeviceManager graphics;
        public Vector2 resolution
        {
            get { return new Vector2(graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight); }
            set { graphics.PreferredBackBufferWidth = Int32.Parse(value.X.ToString()); graphics.PreferredBackBufferHeight = Int32.Parse(value.Y.ToString()); }
        }

        public int antialisingPass
        {
            get { return game.GraphicsDevice.PresentationParameters.MultiSampleCount; }
            set { game.GraphicsDevice.PresentationParameters.MultiSampleCount = value; }
        }

        public BaseEngine(Game game)
            : base(game)
        {
            this.game = game;

            graphics = new GraphicsDeviceManager(game);
            graphics.PreferMultiSampling = true;
            graphics.ApplyChanges();

            game.Content.RootDirectory = "Content";
            game.Components.Add(this);
        }

        public override void Initialize()
        {
            base.Initialize();
        }

        public override void Update(GameTime gameTime)
        {
            entities.UpdateAll(gameTime, camera);
            entities.DrawAll(gameTime);

            base.Update(gameTime);
        }

        public Vector3 GetScreenCenter()
        {
            return new Vector3(game.GraphicsDevice.Viewport.Width / 2, game.GraphicsDevice.Viewport.Height / 2, 0);
        }
    }
}